package users

import (
	"context"
	"star/internal/logic/users"
	"star/internal/model"

	"star/api/users/v1"
)

func (c *ControllerV1) UserList(ctx context.Context, req *v1.UserListReq) (res *v1.UserListRes, err error) {
	query := &model.UserListQuery{
		Username: req.Username,
		Page:     req.Page,
		Size:     req.Size,
	}
	list, total, err := users.GetUserList(ctx, query)
	if err != nil {
		return
	}
	var userList []model.UserItem

	for _, v := range list {
		userList = append(userList, model.UserItem{
			Id:       v.Id,
			Username: v.Username,
			Email:    v.Email,
		})
	}

	res = &v1.UserListRes{
		Total: total,
		List:  userList,
	}
	return
}
